﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MyKTVService;
using MyKTVUtils;

namespace MyKTV02
{
    public partial class frmEdit : Form
    {
        public frmEdit()
        {
            InitializeComponent();
        }
        Service service = new Service();
        private void btnQuery_Click(object sender, EventArgs e)
        {
            string name = txtSingerName.Text;
            string sex = "";
            if (rdoMan.Checked)
            {
                sex = "男";
            }
            else if (rdoWoman.Checked)
            {
                sex = "女";
            }
            else {
                sex = "组合";
            }
            int singerTypeId = Convert.ToInt32(cboSingerType.SelectedValue);
            string singerInfo = txtInfo.Text;
            if (StringUtils.IsBlank(name)) {
                MessageBox.Show("请选择歌手姓名", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;

            }
            else if (StringUtils.IsBlank(photoUrl))
            {
                MessageBox.Show("请选择歌手图片", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;

            }
            else if (StringUtils.IsBlank(singerInfo))
            {
                MessageBox.Show("请选择歌手描述", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;

            }
            else if (singerTypeId==0)
            {
                MessageBox.Show("请选择歌手类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            int result = Sservice.AddSinger(name, singerTypeId, sex, photoUrl, singerInfo);
            if (result > 0)
            {
                MessageBox.Show("添加成功");
                Sservice.RelodSingerList();
            }
            else {
                MessageBox.Show("添加成功");
            }
        }

        private void btnBreak_Click(object sender, EventArgs e)
        {
            this.Close();

        }
        string photoUrl = "";
        private void btnSelect_Click(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();
            op.InitialDirectory = "E:\\JieYeKTV\\WFCH08\\MyKTV02\\MyKTV02\\image";
            op.Filter = "jpg|*.jpg|png|*.png|gif|*.gif";
            DialogResult dr = op.ShowDialog();
            if (dr == DialogResult.OK) {
                photoUrl = op.FileName;
                picPhoto.ImageLocation = photoUrl;
            }
        }
        /// <summary>
        /// 确定是否修改数据，如果是，那么就是true
        /// 如果为false 就是新增
        /// </summary>
        public Boolean isEdit = false;
        private void frmEdit_Load(object sender, EventArgs e)
        {
            BindCboData();
            rdoMan.Checked = true;
           
        }
        SingerService Sservice = new SingerService();
        private void BindCboData()
        {
           this.cboSingerType.DataSource= Sservice.BindCboData();
            cboSingerType.DisplayMember = "singertype_name";
            cboSingerType.ValueMember = "singertype_id";
        }
    }
}
